package tt.dz.egobus.servicemanager.bean;

import org.springframework.core.convert.converter.Converter;
import tt.dz.egobus.bean.BaseBean;
import tt.dz.egobus.servicemanager.business.convert.RedisTopicMessageKeyConverter;

/**
 * @author Anson
 * @date 17-8-25
 * @name redis的key的转换器
 *      各种属性里面,不能含有-这种符号,否则,程序解析出问题
 * @since 1.0.6
 */
public class RedisTopicMessage implements BaseBean {

    private static final long serialVersionUID = 1019146432550143687L;

    /**
     * key的前缀
     */
    private String redisPre;

    /**
     * 事件名称
     */
    private String eventName;

    /**
     * 业务名称
     */
    private String businessKey;

    /**
     * 创建时间
     */
    private long createTime;

    /**
     * 管道名称
     */
    private String channel;

    private transient Converter<RedisTopicMessage, String> messageStringConverter
            = new RedisTopicMessageKeyConverter();

    public String toRedisEventKey() {
        return this.messageStringConverter.convert(this);
    }


    public String getRedisPre() {
        return redisPre;
    }

    public void setRedisPre(String redisPre) {
        this.redisPre = redisPre;
    }

    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }

    public String getBusinessKey() {
        return businessKey;
    }

    public void setBusinessKey(String businessKey) {
        this.businessKey = businessKey;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof RedisTopicMessage)) return false;

        RedisTopicMessage that = (RedisTopicMessage) o;

        if (getCreateTime() != that.getCreateTime()) return false;
        if (getRedisPre() != null ? !getRedisPre().equals(that.getRedisPre()) : that.getRedisPre() != null)
            return false;
        if (getEventName() != null ? !getEventName().equals(that.getEventName()) : that.getEventName() != null)
            return false;
        if (getBusinessKey() != null ? !getBusinessKey().equals(that.getBusinessKey()) : that.getBusinessKey() != null)
            return false;
        return getChannel() != null ? getChannel().equals(that.getChannel()) : that.getChannel() == null;
    }

    @Override
    public int hashCode() {
        int result = getRedisPre() != null ? getRedisPre().hashCode() : 0;
        result = 31 * result + (getEventName() != null ? getEventName().hashCode() : 0);
        result = 31 * result + (getBusinessKey() != null ? getBusinessKey().hashCode() : 0);
        result = 31 * result + (int) (getCreateTime() ^ (getCreateTime() >>> 32));
        result = 31 * result + (getChannel() != null ? getChannel().hashCode() : 0);
        return result;
    }
}